package org.apache.dubbo.demo;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.sample.ITest;
import org.apache.dubbo.sample.tri.GreeterReply;
import org.apache.dubbo.sample.tri.GreeterRequest;
import org.apache.dubbo.sample.tri.PbGreeter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportResource;

@EnableDubbo
@SpringBootApplication
@ImportResource(value = {"classpath:/spring/dubbo-consumer.xml"})
public class ConsumerApplication {

    private static final Logger logger = LoggerFactory.getLogger(ConsumerApplication.class);

    public static void main(String[] args) throws Exception {
        ApplicationContext app = SpringApplication.run(ConsumerApplication.class, args);
        PbGreeter pbGreeter = app.getBean("pbGreeter", PbGreeter.class);
        ITest test = app.getBean("testService", ITest.class);
        for (int i = 0; i < 10000; i++) {
            GreeterRequest build = GreeterRequest.newBuilder().setName("name" + i).build();
            GreeterReply greet = pbGreeter.greet(build);
            logger.error("greet --- {} ", greet);
            logger.error("say --- {} ", test.say("name" + i));
            Thread.sleep(100);
        }

    }
}
